package com.wing.order.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.order.dao.InventoryInoutDetailDao;
import com.wing.order.model.entity.InventoryInoutDetail;
import com.wing.order.model.request.InventoryInoutDetailForm;
import com.wing.order.model.response.InventoryInoutDetailVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 入库计划单明细-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class InventoryInoutDetailServiceImpl extends ServiceImpl<InventoryInoutDetailDao, InventoryInoutDetail> implements InventoryInoutDetailService {

    @Override
    public int add(InventoryInoutDetailForm inventoryInoutDetailForm) {

        //校验

        InventoryInoutDetail inventoryInoutDetail =new InventoryInoutDetail();
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(InventoryInoutDetail.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(inventoryInoutDetailForm, inventoryInoutDetail, copyOptions);

        return baseMapper.insert(inventoryInoutDetail);
    }

    @Override
    public List<InventoryInoutDetailVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<InventoryInoutDetailVO> pageList4app(Page page, Map<String, Object> params) {
        List<InventoryInoutDetailVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public InventoryInoutDetailVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }

    @Override
    public InventoryInoutDetail getInventoryInoutDetail(Long planId, String skuCode) {
        LambdaQueryWrapper<InventoryInoutDetail> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(InventoryInoutDetail :: getPlanId,planId);
        wrapper.eq(InventoryInoutDetail::getSkuCode,skuCode);
        return baseMapper.selectOne(wrapper);
    }
}
